use std::{net::{SocketAddr, UdpSocket}, time::SystemTime};

pub fn new_local_addr() -> SocketAddr {
    let socket = UdpSocket::bind("0.0.0.0:0").unwrap();
    socket.connect("www.baidu.com:80").unwrap();

    socket.local_addr().unwrap()
}

pub fn timestamp() -> String {
    let time = SystemTime::now();
    let dur = time.duration_since(SystemTime::UNIX_EPOCH).unwrap();

    let second = dur.as_secs() % 60;
    let total_minute = dur.as_secs() / 60;
    let minute = total_minute % 60;
    let total_hour = total_minute / 60;
    let hour = total_hour % 24 + 8;
    
    format!("{}:{}:{}", hour, minute, second)
}
